package org.dromara.apartment.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.apartment.domain.vo.FeeKeyVo;
import org.dromara.apartment.domain.bo.FeeKeyBo;
import org.dromara.apartment.service.IFeeKeyService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 杂项费用名称
 * 前端访问路由地址为:/apartment/feeKey
 *
 * @author ckj
 * @date 2025-06-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/feeKey")
public class FeeKeyController extends BaseController {

    private final IFeeKeyService feeKeyService;

    /**
     * 分页查询杂项费用名称列表
     */
    @SaCheckPermission("apartment:feeKey:list")
    @GetMapping("/list")
    public TableDataInfo<FeeKeyVo> list(FeeKeyBo bo, PageQuery pageQuery) {
        return feeKeyService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询杂项费用名称列表
     */
    @SaCheckPermission("apartment:feeKey:list")
    @PostMapping("/getAllList")
    public R<List<FeeKeyVo>> getAllList(@RequestBody FeeKeyBo bo) {
        return R.ok(feeKeyService.queryList(bo));
    }

    /**
     * 查询杂项费用名称树形列表
     */
    @SaCheckPermission("apartment:feeKey:list")
    @PostMapping("/treeList")
    public R<List<FeeKeyVo>> treeList(@RequestBody FeeKeyBo bo) {
        return R.ok(feeKeyService.queryList(bo));
    }

    /**
     * 获取杂项费用名称详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("apartment:feeKey:query")
    @GetMapping("/{id}")
    public R<FeeKeyVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(feeKeyService.queryById(id));
    }

    /**
     * 新增杂项费用名称
     */
    @SaCheckPermission("apartment:feeKey:add")
    @Log(title = "杂项费用名称", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody FeeKeyBo bo) {
        return toAjax(feeKeyService.insertByBo(bo));
    }

    /**
     * 修改杂项费用名称
     */
    @SaCheckPermission("apartment:feeKey:edit")
    @Log(title = "杂项费用名称", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FeeKeyBo bo) {
        return toAjax(feeKeyService.updateByBo(bo));
    }

    /**
     * 删除杂项费用名称
     *
     * @param ids 主键串
     */
    @SaCheckPermission("apartment:feeKey:remove")
    @Log(title = "杂项费用名称", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("ids") Long[] ids) {
        return toAjax(feeKeyService.deleteWithValidByIds(List.of(ids), true));
    }
}
